/******************************************************************************
 * * audio_main.c - implementation of audio main functions
 *
 * *(C) Copyright 2019 Asr International Ltd.
 * * All Rights Reserved
 * ******************************************************************************/
#include "audio_global.h"
//#include "../../../lvgl/lv_misc/lv_fs.h"

/**********************
* GLOBAL VARIABLES
**********************/
typedef lv_fs_file_t ui_file_t;
LV_IMG_DECLARE(music);

enum {
    AUDIO_PLAYER_STATE_IDLE = 0,
    AUDIO_PLAYER_STATE_RUN,
    AUDIO_PLAYER_STATE_PAUSE
};
typedef UINT8 AUDIO_PLAYER_STATE;
static AUDIO_PLAYER_STATE ap_state = AUDIO_PLAYER_STATE_IDLE;
static AUDIO_PLAYER_STATE ap_store_state = AUDIO_PLAYER_STATE_IDLE;
static UINT32     endtime = 0;
static hal_play_info_t current_playinfo;
static UINT32     play_cnt = 0;
static INT32     current_view_index = 0;
static UINT32     current_index = AUDIO_CURRENT_INDEX_INVALID;
lv_task_t * audio_player_task_p = NULL;
audio_info_t audio_info_global;
Audio_Player_Global_Ctrl_t g_AudioPlayerGlobalCtrl;
#if USE_LV_SD_FS
bool  sd_remount_flg = false;
#endif

static void audio_player_music_over_cb(void * para);
static void audio_player_task(lv_task_t * task);
static VOID Audio_Player_All_Songs_Cb(lv_obj_t *pBtn,lv_event_t e);
static VOID Audio_Player_All_Songs_Sub_Cb(lv_obj_t *pBtn,lv_event_t e);
static UINT8 Audio_Player_All_Songs_Handle(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val);
static VOID Audio_Player_Main(VOID);
static UINT8 Audio_Player_Opt_Handle(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val);
static VOID Audio_Player_Pause_Handle(VOID);
static VOID Audio_Player_Play_Handle(VOID);
static VOID Audio_Player_Prev_Handle(VOID);
static VOID Audio_Player_Next_Handle(VOID);
static void volume_end_task(lv_task_t * task);

#if USE_LV_BLUETOOTH != 0
VOID phone_bt_avrcp_connect_message_handle(VOID * msg)
{
    mmi_msg_bt_avrcp_key_t * res_msg = (mmi_msg_bt_avrcp_key_t *)msg;
    printf("bt+++ watch_bt_avrcp_connect_message_handle key_state = %d\n", res_msg->key_state);
    if(MMI_BT_AVRCP_KEY_CNF == res_msg->header.MsgId) {
        if(0 == res_msg->key_state) {
            printf("bt avrcp key pressed ksycode = %2x \n", res_msg->key);
        } else {
            printf("bt avrcp key released ksycode = %2x \n", res_msg->key);
            switch (res_msg->key)
            {
            case AVRCP_KEY_PLAY:
                if(AUDIO_PLAYER_STATE_PAUSE == ap_state)
                {
                    Audio_Player_Play_Handle();
                }
                break;

            case AVRCP_KEY_STOP:
            case AVRCP_KEY_PAUSE:
                if(AUDIO_PLAYER_STATE_RUN == ap_state)
                {
                    Audio_Player_Pause_Handle();
                }
                break;

            case AVRCP_KEY_FORWARD:
                Audio_Player_Next_Handle();
                break;

            case AVRCP_KEY_BACKWARD:
                Audio_Player_Prev_Handle();
                break;
            default:
                break;
            }
        }
    }
}

VOID audio_player_handle_bt_handset_connect_cnf(UINT8 connect)
{
    if(connect)
    {// connected
        if(AUDIO_PLAYER_STATE_RUN == ap_state)
        {
            Audio_Player_Pause_Handle();
            Audio_Player_Play_Handle();
        }
    }
    else
    {// disconnected
        if(AUDIO_PLAYER_STATE_RUN == ap_state)
        {
            Audio_Player_Pause_Handle();
        }
    }
}
#endif

VOID Audio_Player_Audio_Contine(VOID)
{
    printf("ap_store_state is %d in %s\n",ap_store_state,__FUNCTION__);
    if(AUDIO_PLAYER_STATE_RUN == ap_store_state)
    {
        Audio_Player_Play_Handle();
    }
}

VOID Audio_Player_Audio_Stop(VOID)
{
    printf("ap_state is %d in %s\n",ap_state,__FUNCTION__);
    if(AUDIO_PLAYER_STATE_RUN == ap_state)
    {
        Audio_Player_Pause_Handle();
        ap_store_state = AUDIO_PLAYER_STATE_RUN;
    }
    volume_end_task(NULL);
}

BOOL Audio_Player_Is_Running(VOID)
{
    BOOL Result = FALSE;
    if(AUDIO_PLAYER_STATE_RUN == ap_state)
    {
        Result = TRUE;
    }

    printf("Audio_Player_Is_Running state is %d\n",Result);
    return Result;
}

static void store_audio_player_info_to_global(char *path,char *filename,ui_file_t *pfile)
{
    printf("%s,path:%s,filename:%s\n",__FUNCTION__,path,filename);
    char path_temp[AUDIO_PATH_MAX];
    char filename_temp[AUDIO_PATH_MAX];
    UINT32 ret_len = 0;

    if((strlen(filename) + strlen(path) - 1) > AUDIO_PATH_MAX)
    {
        printf("filename and path are too long,can not be saved!\n");
        return;
    }
    memset(path_temp,0,AUDIO_PATH_MAX);
    memset(filename_temp,0,AUDIO_PATH_MAX);
    memcpy(path_temp,path,(strlen(path) - 1)); //without *
    memcpy(filename_temp,filename,strlen(filename));
    play_cnt++;
    lv_fs_seek(pfile, 0);
    lv_fs_write(pfile, &play_cnt, sizeof(UINT32) ,&ret_len);
    if(0 == ret_len)
    {
        printf("write play_cnt in sdfs is wrong!\n");
        return;
    }
    lv_fs_seek(pfile, (play_cnt - 1) * AUDIO_PATH_MAX * 2 + sizeof(UINT32));
    lv_fs_write(pfile, path_temp, AUDIO_PATH_MAX ,&ret_len);
    if(0 == ret_len)
    {
        printf("write path in sdfs is wrong!\n");
        return;
    }
    lv_fs_seek(pfile, (play_cnt - 1) * AUDIO_PATH_MAX * 2 + AUDIO_PATH_MAX + sizeof(UINT32));
    lv_fs_write(pfile, filename_temp, AUDIO_PATH_MAX ,&ret_len);
    if(0 == ret_len)
    {
        printf("write filename in sdfs is wrong!\n");
        return;
    }

    printf("play_cnt:%u\n",play_cnt);
}

static void get_audio_player_info(char* path,ui_file_t *pfile)
{
    printf("%s,path:%s\n",__FUNCTION__,path);
#ifndef BUILD_IN_PC_SIMULATOR
    lv_fs_dir_t dir;
    char *filename = (char*)lv_mem_alloc(AUDIO_PATH_MAX);
    char *newpath = NULL;
    char *fullpathname = NULL;
    const char *extname = NULL;
    int ret = LV_FS_RES_OK;
    uint32_t     endtimetemp = 0;

    memset(&dir, 0, sizeof(dir));
    ret = lv_fs_dir_open(&dir, path);
    if (ret == LV_FS_RES_OK) {
        printf("opendir OK handle:0x%x\n", *(UINT32 *)dir.dir_d);
        while ((ret & 0x0F) == LV_FS_RES_OK) {
            memset(filename, 0, AUDIO_PATH_MAX);
            ret = lv_fs_dir_read(&dir, filename);
            if((ret & 0x0F) == LV_FS_RES_OK)
            {
                printf("-->read file name:%s attr:%x\n", filename, (ret & 0xF0));
                switch ((ret & 0xF0))
                {
                case AUDIO_FILE_ARC:
                    extname = lv_fs_get_ext(filename);
                    printf("-->ext name:%s\n", extname);
                    if((false == strcmp(AUDIO_EXT_NAME,extname)) || (false == strcmp(AUDIO_EXT_NAME_SUB,extname)))
                    {
                        printf("cmp ok-->path:%s,filename%s\n", path,filename);
                        fullpathname = (char*)lv_mem_alloc(strlen(path) + strlen(filename) + 5);
                        memset(fullpathname,0,strlen(path) + strlen(filename) + 5);
                        memcpy(fullpathname,path,(strlen(path) - 1)); //without *
                        strcat(fullpathname,filename);
                        endtimetemp = 0;
                        Hal_File_Get_AudioDurationTime(fullpathname, &endtimetemp);
                        lv_mem_free(fullpathname);
                        printf("the full time is %d in %s\n",endtimetemp,__FUNCTION__);
                        if(endtimetemp)
                        {
                            store_audio_player_info_to_global(path,filename,pfile);
                        }
                        else
                        {
                            printf("the music can not be recorded in the audio list: %s\n",__FUNCTION__);
                        }
                    }
                    break;
                case AUDIO_FILE_DIR:
                    newpath = (char*)lv_mem_alloc(strlen(path) + strlen(filename) + 5);
                    memset(newpath,0,strlen(path) + strlen(filename) + 5);
                    memcpy(newpath,path,(strlen(path) - 1)); //without *
                    strcat(newpath,filename);
                    strcat(newpath,"\\*");
                    get_audio_player_info(newpath,pfile);
                    lv_mem_free(newpath);
                    break;
                case AUDIO_FILE_HID:
                default:
                    break;
                }
            }
        }
        lv_fs_dir_close(&dir);
    } else {
        printf("opendir %s failed!!!\n", path);
    }
    lv_mem_free(filename);
#else
    store_audio_player_info_to_global(path,"11112222333344445555.mp3",pfile);
    store_audio_player_info_to_global(path,"2.mp3",pfile);
    store_audio_player_info_to_global(path,"3.mp3",pfile);
    store_audio_player_info_to_global(path,"4.mp3",pfile);
    store_audio_player_info_to_global(path,"5.mp3",pfile);
    store_audio_player_info_to_global(path,"6.mp3",pfile);
    store_audio_player_info_to_global(path,"7.mp3",pfile);
    store_audio_player_info_to_global(path,"8.mp3",pfile);
    store_audio_player_info_to_global(path,"9.mp3",pfile);
#endif
}

static audio_info_t* get_audio_player_info_from_filesystem(UINT32 index,bool mode)
{
    printf("%s,index:%d\n",__FUNCTION__,index);
    ui_file_t *pfile = NULL;
    UINT32 ret_len = 0;
    int ret = LV_FS_RES_OK;

    char path[6];
    strcpy(path,AUDIO_ROOT_PATH);
#ifndef BUILD_IN_PC_SIMULATOR
    lv_fs_dir_t dir;
    memset(&dir, 0, sizeof(dir));
    ret = lv_fs_dir_open(&dir, path);
    if (ret == LV_FS_RES_OK) {
        printf("opendir OK handle:0x%x in get_audio_player_info_from_filesystem\n", *(UINT32 *)dir.dir_d);
        lv_fs_dir_close(&dir);
#else
    if(1) {
#endif
        pfile = lv_mem_alloc(sizeof(ui_file_t));
        memset(pfile,0,sizeof(ui_file_t));
        ret = lv_fs_open(pfile,ADUIO_FILE_SYSTEM_PATH,LV_FS_MODE_RD);
        printf("ret is %d in %s\n",ret,__FUNCTION__);
        if(LV_FS_RES_OK != ret) {
            printf("D:\\audio_list.nv is not exist!\n");
            play_cnt = 0;
            if(true == mode)
            {
                printf("create D:\\audio_list.nv\n");
                memset(pfile,0,sizeof(ui_file_t));
                ret = lv_fs_open(pfile,ADUIO_FILE_SYSTEM_PATH,LV_FS_MODE_WR);
                if(LV_FS_RES_OK != ret)
                {
                    printf("D:\\audio_list.nv create fail!\n");
                    lv_mem_free(pfile);
                    return NULL;
                }
                lv_fs_close(pfile);
                memset(pfile,0,sizeof(ui_file_t));
                ret = lv_fs_open(pfile,ADUIO_FILE_SYSTEM_PATH,LV_FS_MODE_RD | LV_FS_MODE_APPEND);
                if(LV_FS_RES_OK != ret) {
                    printf("D:\\audio_list.nv second open failed!\n");
                    LV_ASSERT_MEM(pfile->file_d);
                    lv_mem_free(pfile);
                    return NULL;
                }
                lv_fs_seek(pfile, 0);
                lv_fs_write(pfile, &play_cnt, sizeof(UINT32) ,&ret_len);
                if(0 == ret_len)
                {
                    printf("write play_cnt in sdfs is wrong!\n");
                    return NULL;
                }
                get_audio_player_info(path,pfile);
                lv_fs_seek(pfile, 0);
                lv_fs_read(pfile, &play_cnt, sizeof(UINT32) ,&ret_len);
                if(sizeof(UINT32) != ret_len)
                {
                    printf("read play_cnt in sdfs is wrong!\n");
                    lv_fs_close(pfile);
                    lv_mem_free(pfile);
                    return NULL;
                }
                lv_fs_seek(pfile, index * AUDIO_PATH_MAX * 2 + sizeof(UINT32));
                memset(&audio_info_global,0,sizeof(audio_info_t));                // read data
                lv_fs_read(pfile, audio_info_global.path, AUDIO_PATH_MAX ,&ret_len);
                if(AUDIO_PATH_MAX != ret_len)
                {
                    printf("read path in sdfs is wrong!\n");
                    lv_fs_close(pfile);
                    lv_mem_free(pfile);
                    return NULL;
                }
                lv_fs_seek(pfile, index * AUDIO_PATH_MAX * 2 + AUDIO_PATH_MAX + sizeof(UINT32));
                lv_fs_read(pfile, audio_info_global.filename, AUDIO_PATH_MAX ,&ret_len);
                lv_fs_close(pfile);
                lv_mem_free(pfile);
                if(AUDIO_PATH_MAX != ret_len)
                {
                    printf("read filename in sdfs is wrong!\n");
                    return NULL;
                }
            }
            return NULL;
        } else {
            printf("D:\\audio_list.nv is exist!\n");
            if(true == mode)
            {
                printf("create D:\\audio_list.nv\n");
                memset(pfile,0,sizeof(ui_file_t));
                ret = lv_fs_open(pfile,ADUIO_FILE_SYSTEM_PATH,LV_FS_MODE_WR);
                if(LV_FS_RES_OK != ret)
                {
                    printf("D:\\audio_list.nv create fail!\n");
                    lv_mem_free(pfile);
                    return NULL;
                }
                lv_fs_close(pfile);
                memset(pfile,0,sizeof(ui_file_t));
                ret = lv_fs_open(pfile,ADUIO_FILE_SYSTEM_PATH,LV_FS_MODE_RD | LV_FS_MODE_APPEND);
                if(LV_FS_RES_OK != ret) {
                    printf("D:\\audio_list.nv second open failed!\n");
                    LV_ASSERT_MEM(pfile->file_d);
                    lv_mem_free(pfile);
                    return NULL;
                }
                play_cnt = 0;
                lv_fs_seek(pfile, 0);
                lv_fs_write(pfile, &play_cnt, sizeof(UINT32) ,&ret_len);
                if(0 == ret_len)
                {
                    printf("write play_cnt in sdfs is wrong!\n");
                    return NULL;
                }
                get_audio_player_info(path,pfile);
            }
            lv_fs_seek(pfile, 0);
            lv_fs_read(pfile, &play_cnt, sizeof(UINT32) ,&ret_len);
            if(sizeof(UINT32) != ret_len)
            {
                printf("read play_cnt in sdfs is wrong!\n");
                lv_fs_close(pfile);
                lv_mem_free(pfile);
                return NULL;
            }
            lv_fs_seek(pfile, index * AUDIO_PATH_MAX * 2 + sizeof(UINT32));
            memset(&audio_info_global,0,sizeof(audio_info_t));                // read data
            lv_fs_read(pfile, audio_info_global.path, AUDIO_PATH_MAX ,&ret_len);
            if(AUDIO_PATH_MAX != ret_len)
            {
                printf("read path in sdfs is wrong!\n");
                lv_fs_close(pfile);
                lv_mem_free(pfile);
                return NULL;
            }
            lv_fs_seek(pfile, index * AUDIO_PATH_MAX * 2 + AUDIO_PATH_MAX + sizeof(UINT32));
            lv_fs_read(pfile, audio_info_global.filename, AUDIO_PATH_MAX ,&ret_len);
            lv_fs_close(pfile);
            lv_mem_free(pfile);
            if(AUDIO_PATH_MAX != ret_len)
            {
                printf("read filename in sdfs is wrong!\n");
                return NULL;
            }
        }
    } else {
        printf("opendir %s failed in get_audio_player_info_from_filesystem!\n", path);
        play_cnt = 0;
        return NULL;
    }
    return &audio_info_global;
}

static void audio_player_get_endtime(void)
{
    char *path = NULL;
    audio_info_t   *audio_info = get_audio_player_info_from_filesystem(current_index,false);

    printf("audio_info is %lx,current_index is %d in audio_player_get_endtime\n",(unsigned long)audio_info,current_index);
    if(NULL != audio_info)
    {
        path = (char *)lv_mem_alloc(strlen(audio_info->path) + strlen(audio_info->filename) + 1);
        memset(path, 0, strlen(audio_info->path) + strlen(audio_info->filename) + 1);
        strcpy(path,audio_info->path);
        strcat(path,audio_info->filename);
#ifndef BUILD_IN_PC_SIMULATOR
        Hal_File_Get_AudioDurationTime(path, &endtime);
#endif
        printf("endtime is %u in audio_player_get_endtime\n",endtime);
        lv_mem_free(path);
    }
}

static bool audio_player_display_time(void)
{
    UINT32 mseconds;
    UI_Audio_Player_Desc_t *pAudioPlayer   = g_AudioPlayerGlobalCtrl.pChart;

#ifndef BUILD_IN_PC_SIMULATOR
    printf("endtime is %u in audio_player_display_time\n",endtime);
#else
    endtime = 100000;
#endif
    if(AUDIO_PLAYER_STATE_RUN == ap_state) {
        Hal_Audio_Get_PlayInformation(&current_playinfo);
    }

    mseconds = current_playinfo.curPlayTimeMs;
    printf("mseconds is %u in audio_player_display_time\n",mseconds);
    UINT8 sec  = (mseconds / 1000) % 60;         /*[0,59]*/
    UINT8 min  = (mseconds / 1000 / 60) % 60;    /*[0,59]*/

    UINT8 sec_end  = (endtime / 1000) % 60;         /*[0,59]*/
    UINT8 min_end  = (endtime / 1000 / 60) % 60;    /*[0,59]*/

    bool flag;

    char str[14];
    char str1[6];
    char str2[6];

    if(mseconds >= endtime)
    {
        flag = true;
        snprintf(str1, 6, "%02d:%02d", min_end, sec_end);
        snprintf(str2, 6, "%02d:%02d", min_end, sec_end);
        strcpy(str,str1);
        strcat(str, "/");
        strcat(str,str2);
    }
    else
    {
        flag = false;
        snprintf(str1, 6, "%02d:%02d", min, sec);
        snprintf(str2, 6, "%02d:%02d", min_end, sec_end);
        strcpy(str,str1);
        strcat(str, "/");
        strcat(str,str2);
    }

    if(ACT_ID_AUDIO_PLAYER != Nav_Get_Top())
    {
        printf("ACT_ID_AUDIO_PLAYER is not exist in audio_player_display_time\n");
        return (flag);
    }

    lv_label_set_text(pAudioPlayer->TimeLabel.Label, str);

    if(endtime > 0)
    {
        lv_slider_set_range(pAudioPlayer->ProgressSlider.Bar,0,endtime / 1000);

        lv_slider_set_value(pAudioPlayer->ProgressSlider.Bar,mseconds / 1000,LV_ANIM_OFF);

        lv_obj_set_click(pAudioPlayer->ProgressSlider.Bar, false);
    }

    return(flag);
}

static void audio_player_auto_user_interface_update(void)
{
    audio_info_t* audio_info = NULL;
    UI_Audio_Player_Desc_t *pAudioPlayer   = g_AudioPlayerGlobalCtrl.pChart;

    if(ACT_ID_AUDIO_PLAYER != Nav_Get_Top())
    {
        printf("ACT_ID_AUDIO_PLAYER is not exist in audio_player_display_time\n");
        return;
    }

    if(AUDIO_CURRENT_INDEX_INVALID != current_index)
    {
        audio_info = get_audio_player_info_from_filesystem(current_index,false);
        if(NULL != audio_info)
        {
            lv_label_set_text(pAudioPlayer->TitleLabel.Label, audio_info->filename);
        }
        else
        {
            if(AUDIO_PLAYER_STATE_RUN == ap_state)
            {
                Hal_File_Play_End();
                if(NULL != audio_player_task_p)
                {
                    lv_task_del(audio_player_task_p);
                    audio_player_task_p = NULL;
                }
                Framework_Set_Sleep_Lcd_Only(FALSE);
            }
            current_index = AUDIO_CURRENT_INDEX_INVALID;
            ap_state = AUDIO_PLAYER_STATE_IDLE;
            memset(&current_playinfo,0,sizeof(hal_play_info_t));
            endtime = 0;
            lv_label_set_text(pAudioPlayer->TitleLabel.Label, "");
        }
    }
    else
    {
        lv_label_set_text(pAudioPlayer->TitleLabel.Label, "");
    }

    printf("%s,current_index is %u\n",__FUNCTION__,current_index);

    audio_player_display_time();

    if(AUDIO_PLAYER_STATE_RUN == ap_state) {
        lv_label_set_text((lv_obj_t *)pAudioPlayer->BtnBar.ButtonM.Button->child_ll.head, UI_Lang_Get_Text_ById(PHONE_TEXT_ID_PAUSE));
    } else {
        lv_label_set_text((lv_obj_t *)pAudioPlayer->BtnBar.ButtonM.Button->child_ll.head, UI_Lang_Get_Text_ById(PHONE_TEXT_ID_PLAY));
    }
}

static NV_AUDIO_PLAYER_MODE get_audio_player_mode(void)
{
    UINT32 length = sizeof(NV_UI_Audio_Player_t);
    NV_UI_Audio_Player_t * nvm = (NV_UI_Audio_Player_t *)lv_mem_alloc(length);
    NV_AUDIO_PLAYER_MODE audio_player_mode = 0;
    if(length != UI_NV_Read_Req(NV_SECTION_UI_AUDIO_PLAYER_MODE, 0, length, (UINT8 *)nvm)) {
        printf("read audio_player_mode from nvm error\n");
        lv_mem_free(nvm);
        return 0;
    }
    audio_player_mode = nvm->audio_player_mode;
    lv_mem_free(nvm);

    return audio_player_mode;
}

static void set_audio_player_mode(NV_AUDIO_PLAYER_MODE audio_player_mode)
{
    NV_UI_Audio_Player_t * nvm = (NV_UI_Audio_Player_t *)lv_mem_alloc(sizeof(NV_UI_Audio_Player_t));
    memset(nvm,0,sizeof(NV_UI_Audio_Player_t));
    nvm->audio_player_mode = audio_player_mode;
    UI_NV_Write_Req(NV_SECTION_UI_AUDIO_PLAYER_MODE, 0, sizeof(NV_UI_Audio_Player_t), (UINT8 *)nvm);
    lv_mem_free(nvm);
}

static void audio_player_auto_play_handler(void)
{
    printf("%s\n", __FUNCTION__);
    char *path = NULL;

    audio_info_t* audio_info = NULL;

    audio_info = get_audio_player_info_from_filesystem(current_index,false);

    if(NULL == audio_info)
    {
        printf("audio_info is NULL in audio_player_auto_play_handler\n");
        current_index = AUDIO_CURRENT_INDEX_INVALID;
        ap_state = AUDIO_PLAYER_STATE_IDLE;
        if(NULL != audio_player_task_p)
        {
            lv_task_del(audio_player_task_p);
            audio_player_task_p = NULL;
            Framework_Set_Sleep_Lcd_Only(FALSE);
        }
        return;
    }

    memset(&current_playinfo,0,sizeof(hal_play_info_t));

    switch (get_audio_player_mode())
    {
    case NV_AUDIO_ORDER_PLAY:
        if((current_index + 1) == play_cnt)
        {
            ap_state = AUDIO_PLAYER_STATE_PAUSE;
            Framework_Set_Sleep_Lcd_Only(FALSE);
        }
        else
        {
            audio_info = get_audio_player_info_from_filesystem(++current_index,false);
            path = (char *)lv_mem_alloc(strlen(audio_info->path) + strlen(audio_info->filename) + 1);
            memset(path,0,strlen(audio_info->path) + strlen(audio_info->filename) + 1);
            strcpy(path,audio_info->path);
            strcat(path,audio_info->filename);
            audio_player_get_endtime();
            Hal_File_Play_Onetime(path,
                                (HAL_SPEAKER_GAIN)(Setting_Get_Ring_Volume_Req()),
                                audio_player_music_over_cb,
                                NULL,
                                0);
            lv_mem_free(path);
        }
        break;

    case NV_AUDIO_SHUFFLE_PLAY:
        current_index = rand() % (play_cnt);
        audio_player_get_endtime();
        audio_info = get_audio_player_info_from_filesystem(current_index,false);
        path = (char *)lv_mem_alloc(strlen(audio_info->path) + strlen(audio_info->filename) + 1);
        memset(path,0,strlen(audio_info->path) + strlen(audio_info->filename) + 1);
        strcpy(path,audio_info->path);
        strcat(path,audio_info->filename);
        Hal_File_Play_Onetime(path,
                            (HAL_SPEAKER_GAIN)(Setting_Get_Ring_Volume_Req()),
                            audio_player_music_over_cb,
                            NULL,
                            0);
        lv_mem_free(path);
        break;

    case NV_AUDIO_ALL_REPEAT_PLAY:
        if((current_index + 1) == play_cnt)
        {
            audio_info = get_audio_player_info_from_filesystem(0,false);
            path = (char *)lv_mem_alloc(strlen(audio_info->path) + strlen(audio_info->filename) + 1);
            memset(path,0,strlen(audio_info->path) + strlen(audio_info->filename) + 1);
            strcpy(path,audio_info->path);
            strcat(path,audio_info->filename);
            current_index = 0;
            audio_player_get_endtime();
            Hal_File_Play_Onetime(path,
                                (HAL_SPEAKER_GAIN)(Setting_Get_Ring_Volume_Req()),
                                audio_player_music_over_cb,
                                NULL,
                                0);
        }
        else
        {
            audio_info = get_audio_player_info_from_filesystem(++current_index,false);
            path = (char *)lv_mem_alloc(strlen(audio_info->path) + strlen(audio_info->filename) + 1);
            memset(path,0,strlen(audio_info->path) + strlen(audio_info->filename) + 1);
            strcpy(path,audio_info->path);
            strcat(path,audio_info->filename);
            audio_player_get_endtime();
            Hal_File_Play_Onetime(path,
                                (HAL_SPEAKER_GAIN)(Setting_Get_Ring_Volume_Req()),
                                audio_player_music_over_cb,
                                NULL,
                                0);
        }
        lv_mem_free(path);
        break;

    case NV_AUDIO_REPEAT_ONCE_PLAY:
        path = (char *)lv_mem_alloc(strlen(audio_info->path) + strlen(audio_info->filename) + 1);
        memset(path,0,strlen(audio_info->path) + strlen(audio_info->filename) + 1);
        strcpy(path,audio_info->path);
        strcat(path,audio_info->filename);
        audio_player_get_endtime();
        Hal_File_Play_Onetime(path,
                            (HAL_SPEAKER_GAIN)(Setting_Get_Ring_Volume_Req()),
                            audio_player_music_over_cb,
                            NULL,
                            0);
        lv_mem_free(path);
        break;

    default:
        break;
    }
}

static void audio_player_music_over_cb(void * para)
{
    printf("%s\n", __FUNCTION__);
    Hal_File_Play_End();
    audio_player_auto_play_handler();
    audio_player_auto_user_interface_update();
}

#if 0
/**
 * sub-module entry
 * param (in) VOID
 * return  VOID
 */
VOID Audio_Player_Fast_Rewind(VOID)
{
    UINT32 mseconds;
    if(AUDIO_PLAYER_STATE_IDLE == ap_state) {
        return;
    }

    if(AUDIO_PLAYER_STATE_RUN == ap_state)
    {
        Hal_Audio_Get_PlayInformation(&current_playinfo);
    }

    mseconds = current_playinfo.curPlayTimeMs;

    if((mseconds) <= 15000)
    {
        current_playinfo.curPlayTimeMs = 0;
    }
    else
    {
        current_playinfo.curPlayTimeMs = mseconds - 15000;
    }
    current_playinfo.PlayProgress = (INT32)((double)current_playinfo.curPlayTimeMs / endtime * 10000.f);

    audio_info_t* audio_info = get_audio_player_info_from_filesystem(current_index,false);
    char *path = (char *)lv_mem_alloc(strlen(audio_info->path) + strlen(audio_info->filename) + 1);
    memset(path,0,strlen(audio_info->path) + strlen(audio_info->filename) + 1);
    strcpy(path,audio_info->path);
    strcat(path,audio_info->filename);
    audio_player_get_endtime();
    Hal_File_Play_End();
    //memset(&current_playinfo,0,sizeof(hal_play_info_t));
    if(AUDIO_PLAYER_STATE_RUN == ap_state)
    {
        Hal_File_Play_Onetime(path,
                        (HAL_SPEAKER_GAIN)(Setting_Get_Ring_Volume_Req()),
                        audio_player_music_over_cb,
                        NULL,
                        current_playinfo.PlayProgress);
    }

    lv_mem_free(path);
    printf("%s:ringvolume is %s,current_index is %d\n",__FUNCTION__,path,current_index);
    audio_player_display_time();
    audio_player_auto_user_interface_update();
}

/**
 * sub-module entry
 * param (in) VOID
 * return  VOID
 */
VOID Audio_Player_Fast_Forward(VOID)
{
    UINT32 mseconds;
    if(AUDIO_PLAYER_STATE_IDLE == ap_state) {
        return;
    }

    if(AUDIO_PLAYER_STATE_RUN == ap_state)
    {
        Hal_Audio_Get_PlayInformation(&current_playinfo);
    }

    mseconds = current_playinfo.curPlayTimeMs;

    if((mseconds + 15000) >= endtime)
    {
        current_playinfo.curPlayTimeMs = endtime;
    }
    else
    {
        current_playinfo.curPlayTimeMs = mseconds + 15000;
    }
    current_playinfo.PlayProgress = (INT32)((double)current_playinfo.curPlayTimeMs / endtime * 10000.f);

    audio_info_t* audio_info = get_audio_player_info_from_filesystem(current_index,false);
    char *path = (char *)lv_mem_alloc(strlen(audio_info->path) + strlen(audio_info->filename) + 1);
    memset(path,0,strlen(audio_info->path) + strlen(audio_info->filename) + 1);
    strcpy(path,audio_info->path);
    strcat(path,audio_info->filename);
    audio_player_get_endtime();
    Hal_File_Play_End();
    //memset(&current_playinfo,0,sizeof(hal_play_info_t));
    if(AUDIO_PLAYER_STATE_RUN == ap_state)
    {
        Hal_File_Play_Onetime(path,
                        (HAL_SPEAKER_GAIN)(Setting_Get_Ring_Volume_Req()),
                        audio_player_music_over_cb,
                        NULL,
                        current_playinfo.PlayProgress);
    }

    lv_mem_free(path);
    printf("%s:ringvolume is %s,current_index is %d\n",__FUNCTION__,path,current_index);
    audio_player_display_time();
    audio_player_auto_user_interface_update();
}
#endif


static void volume_end_task(lv_task_t * task)
{
    UI_Audio_Player_Desc_t *pAudioPlayer   = g_AudioPlayerGlobalCtrl.pChart;
    if(NULL == pAudioPlayer)
    {
        return;
    }
    if(NULL != pAudioPlayer->VolSlider.Bar)
    {
        if(ACT_ID_AUDIO_PLAYER == Nav_Get_Top())
        {
            lv_obj_del(pAudioPlayer->VolSlider.Bar);
            pAudioPlayer->VolSlider.Bar = NULL;
        }

        if(NULL != pAudioPlayer->VolEndTask)
        {
            lv_task_del(pAudioPlayer->VolEndTask);
            pAudioPlayer->VolEndTask = NULL;
        }
    }
}

static void volume_increase_task(lv_task_t * task)
{
    UI_Audio_Player_Desc_t *pAudioPlayer   = g_AudioPlayerGlobalCtrl.pChart;
    UINT8 Volume;
    Volume = Setting_Get_Ring_Volume_Req();
    if(HAL_AUDIO_SPK_LEVEL_MAX > Volume)
    {
        Volume++;
    }
    Setting_Set_Ring_Volume_Req((HAL_SPEAKER_GAIN)Volume);
    Hal_Audio_SetVolume(Volume);
    pAudioPlayer->VolSlider.Range = HAL_AUDIO_SPK_LEVEL_MAX;
    pAudioPlayer->VolSlider.Value = Setting_Get_Ring_Volume_Req();
    lv_obj_t *VolBar = UI_slider_create(pAudioPlayer->Win,130,pAudioPlayer->VolSlider);
    pAudioPlayer->VolSlider.Bar = VolBar;
    lv_task_t * volume_display_end_task_once = NULL;
    volume_display_end_task_once = lv_task_create(volume_end_task, 1000, LV_TASK_PRIO_HIGH, NULL);
    pAudioPlayer->VolEndTask = volume_display_end_task_once;
    printf("Volume is %d in %s\n",Volume,__FUNCTION__);
}

/**
 * sub-module entry
 * param (in) VOID
 * return  VOID
 */
VOID Audio_Player_Volume_Increase(VOID)
{
    UI_Audio_Player_Desc_t *pAudioPlayer   = g_AudioPlayerGlobalCtrl.pChart;
    if(NULL != pAudioPlayer->VolSlider.Bar)
    {
        lv_obj_del(pAudioPlayer->VolSlider.Bar);
        pAudioPlayer->VolSlider.Bar = NULL;
        if(NULL != pAudioPlayer->VolEndTask)
        {
            lv_task_del(pAudioPlayer->VolEndTask);
            pAudioPlayer->VolEndTask = NULL;
        }
    }
    lv_task_t * volume_increase_task_once = NULL;
    volume_increase_task_once = lv_task_create(volume_increase_task, 100, LV_TASK_PRIO_HIGH, NULL);
    lv_task_once(volume_increase_task_once);
    lv_task_ready(volume_increase_task_once);
}

static void volume_decrease_task(lv_task_t * task)
{
    UI_Audio_Player_Desc_t *pAudioPlayer   = g_AudioPlayerGlobalCtrl.pChart;
    UINT8 Volume;
    Volume = Setting_Get_Ring_Volume_Req();
    if(0 < Volume)
    {
        Volume--;
    }
    Setting_Set_Ring_Volume_Req((HAL_SPEAKER_GAIN)Volume);
    Hal_Audio_SetVolume(Volume);
    pAudioPlayer->VolSlider.Range = HAL_AUDIO_SPK_LEVEL_MAX;
    pAudioPlayer->VolSlider.Value = Setting_Get_Ring_Volume_Req();
    lv_obj_t *VolBar = UI_slider_create(pAudioPlayer->Win,130,pAudioPlayer->VolSlider);
    pAudioPlayer->VolSlider.Bar = VolBar;
    lv_task_t * volume_display_end_task_once = NULL;
    volume_display_end_task_once = lv_task_create(volume_end_task, 1000, LV_TASK_PRIO_HIGH, NULL);
    pAudioPlayer->VolEndTask = volume_display_end_task_once;
    printf("Volume is %d in %s\n",Volume,__FUNCTION__);
}

/**
 * sub-module entry
 * param (in) VOID
 * return  VOID
 */
VOID Audio_Player_Volume_Decrease(VOID)
{
    UI_Audio_Player_Desc_t *pAudioPlayer   = g_AudioPlayerGlobalCtrl.pChart;
    if(NULL != pAudioPlayer->VolSlider.Bar)
    {
        lv_obj_del(pAudioPlayer->VolSlider.Bar);
        pAudioPlayer->VolSlider.Bar = NULL;
        if(NULL != pAudioPlayer->VolEndTask)
        {
            lv_task_del(pAudioPlayer->VolEndTask);
            pAudioPlayer->VolEndTask = NULL;
        }
    }
    lv_task_t * volume_decrease_task_once = NULL;
    volume_decrease_task_once = lv_task_create(volume_decrease_task, 100, LV_TASK_PRIO_HIGH, NULL);
    lv_task_once(volume_decrease_task_once);
    lv_task_ready(volume_decrease_task_once);
}

/**
 * sub-module entry
 * param (in) VOID
 * return  VOID
 */
static VOID Audio_Player_Next_Handle(VOID)
{
    if((AUDIO_PLAYER_STATE_IDLE == ap_state) || (0 == play_cnt)) {
        return;
    }

    if(NV_AUDIO_SHUFFLE_PLAY == get_audio_player_mode())
    {
        current_index = rand() % (play_cnt);
    }
    else
    {
        if(play_cnt == (current_index + 1)) {
            current_index = 0;
        } else {
            current_index++;
        }
    }

    audio_info_t* audio_info = get_audio_player_info_from_filesystem(current_index,false);
    char *path = (char *)lv_mem_alloc(strlen(audio_info->path) + strlen(audio_info->filename) + 1);
    memset(path,0,strlen(audio_info->path) + strlen(audio_info->filename) + 1);
    strcpy(path,audio_info->path);
    strcat(path,audio_info->filename);
    audio_player_get_endtime();
    Hal_File_Play_End();
    memset(&current_playinfo,0,sizeof(hal_play_info_t));
    if(AUDIO_PLAYER_STATE_RUN == ap_state)
    {
        Hal_File_Play_Onetime(path,
                        (HAL_SPEAKER_GAIN)(Setting_Get_Ring_Volume_Req()),
                        audio_player_music_over_cb,
                        NULL,
                        0);
    }

    lv_mem_free(path);
    printf("%s:ringvolume is %s,current_index is %d\n",__FUNCTION__,path,current_index);
    audio_player_display_time();
    audio_player_auto_user_interface_update();
}

/**
 * sub-module entry
 * param (in) VOID
 * return  VOID
 */
static VOID Audio_Player_Prev_Handle(VOID)
{
    if((AUDIO_PLAYER_STATE_IDLE == ap_state) || (0 == play_cnt)) {
        return;
    }

    if(NV_AUDIO_SHUFFLE_PLAY == get_audio_player_mode())
    {
        current_index = rand() % (play_cnt);
    }
    else
    {
        if(0 == current_index) {
            current_index = play_cnt - 1;
        } else {
            current_index--;
        }
    }

    audio_info_t* audio_info = get_audio_player_info_from_filesystem(current_index,false);
    char *path = (char *)lv_mem_alloc(strlen(audio_info->path) + strlen(audio_info->filename) + 1);
    memset(path,0,strlen(audio_info->path) + strlen(audio_info->filename) + 1);
    strcpy(path,audio_info->path);
    strcat(path,audio_info->filename);
    audio_player_get_endtime();
    Hal_File_Play_End();
    memset(&current_playinfo,0,sizeof(hal_play_info_t));
    if(AUDIO_PLAYER_STATE_RUN == ap_state)
    {
        Hal_File_Play_Onetime(path,
                        (HAL_SPEAKER_GAIN)(Setting_Get_Ring_Volume_Req()),
                        audio_player_music_over_cb,
                        NULL,
                        0);
    }

    lv_mem_free(path);
    printf("%s:ringvolume is %s,current_index is %d\n",__FUNCTION__,path,current_index);
    audio_player_display_time();
    audio_player_auto_user_interface_update();
}

/**
 * sub-module entry
 * param (in) VOID
 * return  VOID
 */
static VOID Audio_Player_Play_Handle(VOID)
{
    UINT8 Volume = 0;
    If_Setting_Play_Tone_t *PlayToneReq;
    PlayToneReq = (If_Setting_Play_Tone_t *)Hal_Mem_Alloc(sizeof(If_Setting_Play_Tone_t));
    PlayToneReq->PlayCtrl = IF_SETTING_PLAY_TONS_START;
    PlayToneReq->ToneType = IF_SETTING_TONS_TYPE_AUDIO_PLAYER;
    Setting_Play_Tone_Req(PlayToneReq);
    audio_info_t* audio_info = get_audio_player_info_from_filesystem(current_index,false);
    char *path = (char *)lv_mem_alloc(strlen(audio_info->path) + strlen(audio_info->filename) + 1);
    memset(path,0,strlen(audio_info->path) + strlen(audio_info->filename) + 1);
    strcpy(path,audio_info->path);
    strcat(path,audio_info->filename);
    audio_player_get_endtime();
    Hal_File_Play_Onetime(path,
                    (HAL_SPEAKER_GAIN)(Setting_Get_Ring_Volume_Req()),
                    audio_player_music_over_cb,
                    NULL,
                    current_playinfo.PlayProgress);
    Volume = Setting_Get_Ring_Volume_Req();
    printf("%s,Volume is %d!\n",__FUNCTION__,Volume);
    lv_mem_free(path);

    printf("%s,SD card is captured by user!\n",__FUNCTION__);
    ap_state = AUDIO_PLAYER_STATE_RUN;
    Framework_Set_Sleep_Lcd_Only(TRUE);
    printf("%s\n",__FUNCTION__);
    audio_player_auto_user_interface_update();
    if(NULL == audio_player_task_p)
    {
        audio_player_task_p = lv_task_create(audio_player_task, 1000, LV_TASK_PRIO_MID, NULL);
    }
}

/**
 * sub-module entry
 * param (in) VOID
 * return  VOID
 */
static VOID Audio_Player_Pause_Handle(VOID)
{
    If_Setting_Play_Tone_t *PlayToneReq;
    PlayToneReq = (If_Setting_Play_Tone_t *)Hal_Mem_Alloc(sizeof(If_Setting_Play_Tone_t));
    PlayToneReq->PlayCtrl = IF_SETTING_PLAY_TONS_STOP;
    PlayToneReq->ToneType = IF_SETTING_TONS_TYPE_AUDIO_PLAYER;
    Setting_Play_Tone_Req(PlayToneReq);
    ap_state = AUDIO_PLAYER_STATE_PAUSE;
    ap_store_state = AUDIO_PLAYER_STATE_PAUSE;
    audio_player_auto_user_interface_update();
    Hal_Audio_Get_PlayInformation(&current_playinfo);
    printf("%s:curPlayTimeMs is %d,PlayProgress is %d\n",__FUNCTION__,current_playinfo.curPlayTimeMs,current_playinfo.PlayProgress);
    Hal_File_Play_End();
    Framework_Set_Sleep_Lcd_Only(FALSE);
    if(NULL != audio_player_task_p)
    {
        lv_task_del(audio_player_task_p);
        audio_player_task_p = NULL;
    }
}

/**
 * sub-module entry
 * param (in) VOID
 * return  VOID
 */
VOID Audio_Player_All_Songs_Refresh(VOID)
{
    if(AUDIO_PLAYER_STATE_RUN == ap_state)
    {
        Audio_Player_Pause_Handle();
    }
    audio_info_t* audio_info = get_audio_player_info_from_filesystem(0,true);

    if(NULL == audio_info)
    {
        printf("%s,audio_info is NULL!\n",__FUNCTION__);
       // return LV_RES_OK;
    }
    audio_info = NULL;

    if((current_index >= play_cnt)
        && (AUDIO_CURRENT_INDEX_INVALID != current_index))
    {
        current_index = 0;
    }
    Nav_Forward(ACT_ID_ANY, ACT_ID_AUDIO_PLAYER_OPT, NULL, NULL);
    Audio_Player_All_Songs_Cb(NULL,LV_EVENT_CLICKED);
}

/**
 * sub-module entry
 * param (in) VOID
 * return  UINT8
 */
UINT8 Audio_Player_All_Songs_Prev_Handle(VOID)
{
    UINT8 Result = 0;
    audio_info_t* audio_info = NULL;
    UI_Normal_List_Only_Desc_t *AudioPlayerAllSongs     = g_AudioPlayerGlobalCtrl.pAllSongsChart;
    UINT32  index = 0;
    UINT32  count = 0;

    if(play_cnt <= 6)
    {
        return Result;
    }

    if(current_view_index)
    {
        current_view_index--;
    }
    else
    {
        current_view_index = play_cnt - 1;
    }

    printf("%s,chartindex is %d\n",__FUNCTION__,g_AudioPlayerGlobalCtrl.ChartIndex);
    if(g_AudioPlayerGlobalCtrl.ChartIndex)
    {
        g_AudioPlayerGlobalCtrl.ChartIndex--;
        return Result;
    }

    index = current_view_index;
    if(play_cnt >= 6)
    {
        count = 6;
    }
    else
    {
        count = play_cnt;
    }

    lv_obj_user_data_t * user_data = NULL;
    for(UINT32 i = 0; i < count; i++) {
        audio_info = get_audio_player_info_from_filesystem(index,false);
        if(NULL == audio_info)
        {
            printf("%s,audio_info is NULL!\n",__FUNCTION__);
        }
        lv_label_set_text((lv_obj_t *)AudioPlayerAllSongs->List.ButtonList[i].Button->child_ll.head,
                            audio_info->filename);
        user_data = lv_obj_get_user_data_ptr(AudioPlayerAllSongs->List.ButtonList[i].Button);
        user_data->user_num = index;
        lv_label_set_long_mode((lv_obj_t *)AudioPlayerAllSongs->List.ButtonList[i].Button->child_ll.head,
                                LV_LABEL_LONG_SROLL);
        if(0 == i)
        {
            lv_list_focus_btn(lv_obj_get_parent(lv_obj_get_parent(AudioPlayerAllSongs->List.ButtonList[i].Button)),
                                        AudioPlayerAllSongs->List.ButtonList[i].Button);
        }

        if(index + 1 == play_cnt)
        {
            index = 0;
        }
        else
        {
            index++;
        }

        Result = 1;
    }
    return Result;
}

/**
 * sub-module entry
 * param (in) VOID
 * return  UINT8
 */
UINT8 Audio_Player_All_Songs_Next_Handle(VOID)
{
    UINT8 Result = 0;
    audio_info_t* audio_info = NULL;
    UI_Normal_List_Only_Desc_t *AudioPlayerAllSongs     = g_AudioPlayerGlobalCtrl.pAllSongsChart;
    UINT32  index = 0;
    UINT32  count = 0;

    if(play_cnt <= 6)
    {
        return Result;
    }

    if(current_view_index == play_cnt - 1)
    {
        current_view_index = 0;
    }
    else
    {
        current_view_index++;
    }

    printf("%s,chartindex is %d\n",__FUNCTION__,g_AudioPlayerGlobalCtrl.ChartIndex);
    if(g_AudioPlayerGlobalCtrl.ChartIndex < 5)
    {
        g_AudioPlayerGlobalCtrl.ChartIndex++;
        return Result;
    }

    if(current_view_index - 5 < 0)
    {
        index = play_cnt + current_view_index - 5;
    }
    else
    {
        index = current_view_index - 5;
    }
    if(play_cnt >= 6)
    {
        count = 6;
    }
    else
    {
        count = play_cnt;
    }

    lv_obj_user_data_t * user_data = NULL;
    for(UINT32 i = 0; i < count; i++) {
        audio_info = get_audio_player_info_from_filesystem(index,false);
        if(NULL == audio_info)
        {
            printf("%s,audio_info is NULL!\n",__FUNCTION__);
        }
        lv_label_set_text((lv_obj_t *)AudioPlayerAllSongs->List.ButtonList[i].Button->child_ll.head,
                            audio_info->filename);
        user_data = lv_obj_get_user_data_ptr(AudioPlayerAllSongs->List.ButtonList[i].Button);
        user_data->user_num = index;
        lv_label_set_long_mode((lv_obj_t *)AudioPlayerAllSongs->List.ButtonList[i].Button->child_ll.head,
                                LV_LABEL_LONG_SROLL);
        if(5 == i)
        {
            lv_list_focus_btn(lv_obj_get_parent(lv_obj_get_parent(AudioPlayerAllSongs->List.ButtonList[i].Button)),
                                        AudioPlayerAllSongs->List.ButtonList[i].Button);
        }
        if(index + 1 == play_cnt)
        {
            index = 0;
        }
        else
        {
            index++;
        }

        Result = 1;
    }
    return Result;
}

/**
 * entry of audio player APP
 * param (in) void
 * return  void
 */
static UINT8 Audio_Player_All_Songs_Handle(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val)
{
    UINT8 Result = 0;

    // handle the return key
    if (KEY_RELEASED == key_sta)
    {
        if (KEY_SOFTRIGHT == key_val)
        {
            Nav_Back(ACT_ID_ANY);
            Result = 1;
        }
        else if (KEY_END == key_val)
        {
            Nav_Home(ACT_ID_ANY);
            Result = 1;
        }
        else if (KEY_SOFTLEFT == key_val)
        {
            Audio_Player_All_Songs_Refresh();
            Result = 1;
        }
        else if (KEY_UP == key_val)
        {
            Result = Audio_Player_All_Songs_Prev_Handle();
        }
        else if (KEY_DOWN == key_val)
        {
            Result = Audio_Player_All_Songs_Next_Handle();
        }
    }

    return(Result);   // temp
}

/**
 * sub-module entry
 * param (in) lv_obj_t *pBtn
 * return  lv_res_t
 */
static VOID Audio_Player_All_Songs_Sub_Cb(lv_obj_t *pBtn,lv_event_t e)
{
    if(LV_EVENT_CLICKED != e) return;
    if(0 == play_cnt)
    {
        printf("%s,play_cnt is 0!\n",__FUNCTION__);
        return;
    }
    char *path;
    //update the current_index
    lv_obj_user_data_t * user_data = lv_obj_get_user_data_ptr(pBtn);
    current_index = user_data->user_num;
    audio_info_t* audio_info = get_audio_player_info_from_filesystem(current_index,false);
    //hal_play
    if(AUDIO_PLAYER_STATE_RUN == ap_state)
    {
        Hal_File_Play_End();
    }
    memset(&current_playinfo,0,sizeof(hal_play_info_t));
    ap_state = AUDIO_PLAYER_STATE_RUN;
    Framework_Set_Sleep_Lcd_Only(TRUE);
    path = (char *)lv_mem_alloc(strlen(audio_info->path) + strlen(audio_info->filename) + 1);
    memset(path,0,strlen(audio_info->path) + strlen(audio_info->filename) + 1);
    strcpy(path,audio_info->path);
    strcat(path,audio_info->filename);
    printf("%s,path:%s\n",__FUNCTION__,path);
    Hal_File_Play_Onetime(path,
                          (HAL_SPEAKER_GAIN)(Setting_Get_Ring_Volume_Req()),
                          audio_player_music_over_cb,
                          NULL,
                          0);

    lv_mem_free(path);
    if(NULL == audio_player_task_p)
    {
        audio_player_task_p = lv_task_create(audio_player_task, 1000, LV_TASK_PRIO_MID, NULL);
    }
    Nav_Forward(ACT_ID_ANY, ACT_ID_AUDIO_PLAYER, NULL, NULL);

    return;
}

/**
 * Common Process UI Create event
 * param (in) pDesc:  VOID *
 * return  void
 */
VOID Audio_Player_All_Songs_On_Create(VOID *pDesc)
{
    UI_Normal_List_Only_Desc_t *AudioPlayerAllSongs     = pDesc;
    g_AudioPlayerGlobalCtrl.pAllSongsChart = pDesc;
    audio_info_t* audio_info = NULL;

    UINT32  count = 0;
    UINT32  index = 0;

    if(AUDIO_CURRENT_INDEX_INVALID != current_index)
    {
        if(play_cnt > 6)
        {
            current_view_index = current_index;
        }
        else
        {
            current_view_index = 0;
        }
    }
    else
    {
        current_view_index = 0;
    }

    if(play_cnt >= 6)
    {
        count = 6;
    }
    else
    {
        count = play_cnt;
    }

    lv_obj_user_data_t * user_data = NULL;
    for(UINT32 i = 0; i < count; i++) {
        if(current_view_index + i >= play_cnt)
        {
            index = current_view_index + i - play_cnt;
        }
        else
        {
            index = current_view_index + i;
        }

        audio_info = get_audio_player_info_from_filesystem(index,false);
        if(NULL == audio_info)
        {
            printf("%s,audio_info is NULL!\n",__FUNCTION__);
        }
        lv_label_set_text((lv_obj_t *)AudioPlayerAllSongs->List.ButtonList[i].Button->child_ll.head,
                            audio_info->filename);
        user_data = lv_obj_get_user_data_ptr(AudioPlayerAllSongs->List.ButtonList[i].Button);
        user_data->user_num = index;
        lv_label_set_long_mode((lv_obj_t *)AudioPlayerAllSongs->List.ButtonList[i].Button->child_ll.head,
                                LV_LABEL_LONG_SROLL);
    }

    if (0 == count)
    {
        lv_obj_add_style(AudioPlayerAllSongs->List.ButtonList[0].Button, LV_BTN_PART_MAIN, &lv_style_transp);
    }
}

/**
 * Common Process UI destroy event
 * param (in) pDesc:  VOID *
 * return  void
 */
VOID Audio_Player_All_Songs_Destory(VOID *pDesc)
{
    UI_Normal_List_Only_Desc_t *AudioPlayerAllSongs     = pDesc;
    Hal_Mem_Free(AudioPlayerAllSongs->List.ButtonList);
    AudioPlayerAllSongs->List.ButtonList = NULL;
    current_view_index = 0;
    g_AudioPlayerGlobalCtrl.ChartIndex = 0;
    g_AudioPlayerGlobalCtrl.pAllSongsChart = NULL;
}

/**
 * sub-module entry
 * param (in) lv_obj_t *pBtn
 * return  lv_res_t
 */
static VOID Audio_Player_All_Songs_Cb(lv_obj_t *pBtn, lv_event_t e)
{
    Nav_Func_List_t            FuncList;
    UI_Normal_List_Only_Desc_t *AudioPlayerAllSongs     = NULL;
    UI_Button_Desc_t           *ButtonList = NULL;
    UINT32  count = 0;
    UINT32  i = 0;

    if(LV_EVENT_CLICKED != e) return;
    if(play_cnt) {
        get_audio_player_info_from_filesystem(0,false);
    } else {
        get_audio_player_info_from_filesystem(0,true);
    }

    if(0 == play_cnt)
    {
        printf("%s,play_cnt is 0!\n",__FUNCTION__);
    }

    if(play_cnt >= 6)
    {
        count = 6;
    }
    else if(0 == play_cnt)
    {
        count = 1;
    }
    else
    {
        count = play_cnt;
    }
    AudioPlayerAllSongs = (UI_Normal_List_Only_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Normal_List_Only_Desc_t));
    Hal_Mem_Set(AudioPlayerAllSongs, 0, sizeof(UI_Normal_List_Only_Desc_t));

    ButtonList = (UI_Button_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Button_Desc_t) * count);
    Hal_Mem_Set(ButtonList, 0, sizeof(UI_Button_Desc_t) * count);

    AudioPlayerAllSongs->TitleBar.TxtId      = PHONE_TEXT_ID_ALL_SONGS;
    AudioPlayerAllSongs->TitleBar.TxtAlign   = LV_LABEL_ALIGN_CENTER;
    AudioPlayerAllSongs->TitleBar.LabelAlign = LV_ALIGN_IN_TOP_MID;

    AudioPlayerAllSongs->List.ListButtonCnt = count;
    AudioPlayerAllSongs->List.Index         = 0;
    AudioPlayerAllSongs->List.ButtonList    = ButtonList;

    for (i = 0; i < count; i++)
    {
        ButtonList[i].ButtonIndex = i;
        ButtonList[i].TxtId       = LV_LANG_TXT_ID_NONE;
        ButtonList[i].BtnTxt      = "";
        ButtonList[i].ReleaseFun = Audio_Player_All_Songs_Sub_Cb;
        ButtonList[i].Valid      = true;
    }

    AudioPlayerAllSongs->BtnBar.ButtonR.TxtId = PHONE_TEXT_ID_BACK;
    AudioPlayerAllSongs->BtnBar.ButtonR.Valid = true;

    AudioPlayerAllSongs->BtnBar.ButtonM.TxtId = PHONE_TEXT_ID_OK;
    AudioPlayerAllSongs->BtnBar.ButtonM.Valid = true;

    AudioPlayerAllSongs->BtnBar.ButtonL.TxtId = PHONE_TEXT_ID_REFRESH_LIST;
    AudioPlayerAllSongs->BtnBar.ButtonL.Valid = true;

    AudioPlayerAllSongs->KeyFunc = Audio_Player_All_Songs_Handle;

    FuncList.OnShow         = (Void_P_Func_t)UI_Normal_List_Only_Create;
    FuncList.OnHide         = NULL;
    FuncList.OnCreate       = Audio_Player_All_Songs_On_Create;
    FuncList.OnDestroy      = Audio_Player_All_Songs_Destory;   // temp
    FuncList.OnSaveState    = NULL;     // temp
    FuncList.OnRestoreState = Audio_Player_All_Songs_On_Create; // temp

    Nav_Forward(ACT_ID_ANY, ACT_ID_AUDIO_PLAYER_ALL_SONGS, &FuncList, (void *)AudioPlayerAllSongs);
    return;
}

/**
 * sub-module entry
 * param (in) lv_obj_t *pBtn
 * return  lv_res_t
 */
VOID Audio_Player_Sub_Setting_Cb(lv_obj_t *pBtn, lv_event_t e)
{
    if(LV_EVENT_CLICKED != e) return;
    lv_obj_user_data_t * user_data = lv_obj_get_user_data_ptr(pBtn);
    UI_Normal_List_Only_Desc_t *AudioPlayerSetting     = g_AudioPlayerGlobalCtrl.pSettingChart;
    set_audio_player_mode((NV_AUDIO_PLAYER_MODE)user_data->user_num);
    lv_img_set_src(lv_obj_get_child_back(AudioPlayerSetting->List.ButtonList[0].Button,NULL),
                    SYMBOL_NOT_CHECKED);
    lv_img_set_src(lv_obj_get_child_back(AudioPlayerSetting->List.ButtonList[1].Button,NULL),
                    SYMBOL_NOT_CHECKED);
    lv_img_set_src(lv_obj_get_child_back(AudioPlayerSetting->List.ButtonList[2].Button,NULL),
                    SYMBOL_NOT_CHECKED);
    lv_img_set_src(lv_obj_get_child_back(AudioPlayerSetting->List.ButtonList[3].Button,NULL),
                    SYMBOL_NOT_CHECKED);
    //change the sysbol to checked
    lv_img_set_src(lv_obj_get_child_back(pBtn,NULL),
                    SYMBOL_CHECKED);

    return;
}

/**
 * Common Process UI destroy event
 * param (in) pDesc:  VOID *
 * return  void
 */
VOID Audio_Player_Setting_Destory(VOID *pDesc)
{
    g_AudioPlayerGlobalCtrl.pSettingChart     = NULL;
    UI_Normal_List_Only_Desc_t *AudioPlayerSetting     = pDesc;
    Hal_Mem_Free(AudioPlayerSetting->List.ButtonList);
    AudioPlayerSetting->List.ButtonList = NULL;
}

/**
 * Common Process UI Create event
 * param (in) pDesc:  VOID *
 * return  void
 */
VOID Audio_Player_Setting_On_Create(VOID *pDesc)
{
    lv_obj_user_data_t * user_data = NULL;
    g_AudioPlayerGlobalCtrl.pSettingChart     = pDesc;
    UI_Normal_List_Only_Desc_t *AudioPlayerSetting     = pDesc;
    user_data = lv_obj_get_user_data_ptr(AudioPlayerSetting->List.ButtonList[0].Button);
    user_data->user_num = 0;
    user_data = lv_obj_get_user_data_ptr(AudioPlayerSetting->List.ButtonList[1].Button);
    user_data->user_num = 1;
    user_data = lv_obj_get_user_data_ptr(AudioPlayerSetting->List.ButtonList[2].Button);
    user_data->user_num = 2;
    user_data = lv_obj_get_user_data_ptr(AudioPlayerSetting->List.ButtonList[3].Button);
    user_data->user_num = 3;
}

/**
 * sub-module entry
 * param (in) lv_obj_t *pBtn
 * return  lv_res_t
 */
VOID Audio_Player_Setting_Cb(lv_obj_t *pBtn, lv_event_t e)
{
    if(LV_EVENT_CLICKED != e) return;
    Nav_Func_List_t            FuncList;
    UI_Normal_List_Only_Desc_t *AudioPlayerSetting     = NULL;
    UI_Button_Desc_t           *ButtonList = NULL;
    NV_AUDIO_PLAYER_MODE Mode = get_audio_player_mode();

    AudioPlayerSetting = (UI_Normal_List_Only_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Normal_List_Only_Desc_t));
    Hal_Mem_Set(AudioPlayerSetting, 0, sizeof(UI_Normal_List_Only_Desc_t));

    ButtonList = (UI_Button_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Button_Desc_t) * 4);
    Hal_Mem_Set(ButtonList, 0, sizeof(UI_Button_Desc_t) * 4);

    AudioPlayerSetting->TitleBar.TxtId      = PHONE_TEXT_ID_SETTING;
    AudioPlayerSetting->TitleBar.TxtAlign   = LV_LABEL_ALIGN_CENTER;
    AudioPlayerSetting->TitleBar.LabelAlign = LV_ALIGN_IN_TOP_MID;

    AudioPlayerSetting->List.ListButtonCnt = 4;
    AudioPlayerSetting->List.Index         = 0;
    AudioPlayerSetting->List.ButtonList    = ButtonList;

    ButtonList[0].ButtonIndex = 0;
    ButtonList[0].TxtId       = PHONE_TEXT_ID_ORDER_PLAY;
    ButtonList[0].SymbolId1  = SYMBOL_NOT_CHECKED;
    ButtonList[0].ReleaseFun = Audio_Player_Sub_Setting_Cb;
    ButtonList[0].Valid      = true;

    ButtonList[1].ButtonIndex = 1;
    ButtonList[1].TxtId       = PHONE_TEXT_ID_SHUFFLE_PLAY;
    ButtonList[1].SymbolId1  = SYMBOL_NOT_CHECKED;
    ButtonList[1].ReleaseFun = Audio_Player_Sub_Setting_Cb;
    ButtonList[1].Valid      = true;

    ButtonList[2].ButtonIndex = 2;
    ButtonList[2].TxtId       = PHONE_TEXT_ID_ALL_REPEAT_PLAY;
    ButtonList[2].SymbolId1  = SYMBOL_NOT_CHECKED;
    ButtonList[2].ReleaseFun = Audio_Player_Sub_Setting_Cb;
    ButtonList[2].Valid      = true;

    ButtonList[3].ButtonIndex = 3;
    ButtonList[3].TxtId       = PHONE_TEXT_ID_REPEAT_ONCE_PLAY;
    ButtonList[3].SymbolId1  = SYMBOL_NOT_CHECKED;
    ButtonList[3].ReleaseFun = Audio_Player_Sub_Setting_Cb;
    ButtonList[3].Valid      = true;

    ButtonList[Mode].SymbolId1  = SYMBOL_CHECKED;

    AudioPlayerSetting->BtnBar.ButtonR.TxtId = PHONE_TEXT_ID_BACK;
    AudioPlayerSetting->BtnBar.ButtonR.Valid = true;

    AudioPlayerSetting->BtnBar.ButtonM.TxtId = PHONE_TEXT_ID_OK;
    AudioPlayerSetting->BtnBar.ButtonM.Valid = true;

    AudioPlayerSetting->KeyFunc = Audio_Player_Opt_Handle;

    FuncList.OnShow         = (Void_P_Func_t)UI_Normal_List_Only_Create;
    FuncList.OnHide         = NULL;
    FuncList.OnCreate       = Audio_Player_Setting_On_Create;
    FuncList.OnDestroy      = Audio_Player_Setting_Destory;   // temp
    FuncList.OnSaveState    = NULL;     // temp
    FuncList.OnRestoreState = Audio_Player_Setting_On_Create; // temp

    Nav_Forward(ACT_ID_ANY, ACT_ID_AUDIO_PLAYER_SETTING, &FuncList, (void *)AudioPlayerSetting);

    return;
}

/**
 * entry of audio player APP
 * param (in) void
 * return  void
 */
static UINT8 Audio_Player_Opt_Handle(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val)
{
    UINT8 Result = 0;

    // handle the return key
    if (KEY_RELEASED == key_sta)
    {
        if (KEY_SOFTRIGHT == key_val)
        {
            Nav_Back(ACT_ID_ANY);
            Result = 1;
        }
        else if (KEY_END == key_val)
        {
            Nav_Home(ACT_ID_ANY);
            Result = 1;
        }
    }

    return(Result);   // temp
}

/**
 * Common Process UI destroy event
 * param (in) pDesc:  VOID *
 * return  void
 */
VOID Audio_Player_Opt_Destory(VOID *pDesc)
{
    UI_Normal_List_Only_Desc_t *AudioPlayerOpt     = pDesc;
    Hal_Mem_Free(AudioPlayerOpt->List.ButtonList);
    AudioPlayerOpt->List.ButtonList = NULL;
}

/**
 * sub-module entry
 * param (in) VOID
 * return  VOID
 */
VOID Audio_Player_Opt(VOID)
{
    Nav_Func_List_t            FuncList;
    UI_Normal_List_Only_Desc_t *AudioPlayerOpt     = NULL;
    UI_Button_Desc_t           *ButtonList = NULL;

    AudioPlayerOpt = (UI_Normal_List_Only_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Normal_List_Only_Desc_t));
    Hal_Mem_Set(AudioPlayerOpt, 0, sizeof(UI_Normal_List_Only_Desc_t));

    ButtonList = (UI_Button_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Button_Desc_t) * 2);
    Hal_Mem_Set(ButtonList, 0, sizeof(UI_Button_Desc_t) * 2);

    AudioPlayerOpt->TitleBar.TxtId      = PHONE_TEXT_ID_OPT;
    AudioPlayerOpt->TitleBar.TxtAlign   = LV_LABEL_ALIGN_CENTER;
    AudioPlayerOpt->TitleBar.LabelAlign = LV_ALIGN_IN_TOP_MID;

    AudioPlayerOpt->List.ListButtonCnt = 2;
    AudioPlayerOpt->List.Index         = 0;
    AudioPlayerOpt->List.ButtonList    = ButtonList;

    ButtonList[0].ButtonIndex = 0;
    ButtonList[0].TxtId       = PHONE_TEXT_ID_ALL_SONGS;
    ButtonList[0].ReleaseFun = Audio_Player_All_Songs_Cb;
    ButtonList[0].Valid      = true;

    ButtonList[1].ButtonIndex = 1;
    ButtonList[1].TxtId       = PHONE_TEXT_ID_SETTING;
    ButtonList[1].ReleaseFun = Audio_Player_Setting_Cb;
    ButtonList[1].Valid      = true;

    AudioPlayerOpt->BtnBar.ButtonR.TxtId = PHONE_TEXT_ID_BACK;
    AudioPlayerOpt->BtnBar.ButtonR.Valid = true;

    AudioPlayerOpt->BtnBar.ButtonM.TxtId = PHONE_TEXT_ID_OK;
    AudioPlayerOpt->BtnBar.ButtonM.Valid = true;

    AudioPlayerOpt->KeyFunc = Audio_Player_Opt_Handle;

    FuncList.OnShow         = (Void_P_Func_t)UI_Normal_List_Only_Create;
    FuncList.OnHide         = NULL;
    FuncList.OnCreate       = NULL;
    FuncList.OnDestroy      = Audio_Player_Opt_Destory;   // temp
    FuncList.OnSaveState    = NULL;     // temp
    FuncList.OnRestoreState = NULL; // temp

    Nav_Forward(ACT_ID_ANY, ACT_ID_AUDIO_PLAYER_OPT, &FuncList, (void *)AudioPlayerOpt);
}

/**
 * entry of audio player APP
 * param (in) void
 * return  void
 */
UINT8 Audio_Player_Main_Handle(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val)
{
    UINT8 Result = 0;

    // handle the return key
    if (KEY_RELEASED == key_sta)
    {
        if (KEY_SOFTRIGHT == key_val)
        {
            Nav_Back(ACT_ID_ANY);
            Result = 1;
        }
        else if (KEY_END == key_val)
        {
            Nav_Home(ACT_ID_ANY);
            Result = 1;
        }
        else if (KEY_SOFTLEFT == key_val)
        {
            Audio_Player_Opt();
            Result = 1;
        }
        else if (KEY_OK == key_val)
        {
            if(AUDIO_PLAYER_STATE_RUN == ap_state)
            {
                Audio_Player_Pause_Handle();
            }
            else if(AUDIO_PLAYER_STATE_PAUSE == ap_state)
            {
                Audio_Player_Play_Handle();
            }
            Result = 1;
        }
        else if (KEY_UP == key_val)
        {
            Audio_Player_Volume_Increase();
            Result = 1;
        }
        else if (KEY_DOWN == key_val)
        {
            Audio_Player_Volume_Decrease();
            Result = 1;
        }
        else if (KEY_RIGHT == key_val)
        {
            Audio_Player_Next_Handle();
            Result = 1;
        }
        else if (KEY_LEFT == key_val)
        {
            Audio_Player_Prev_Handle();
            Result = 1;
        }
    }

    return(Result);   // temp
}

/**
 * Common Process UI destroy event
 * param (in) pDesc:  VOID *
 * return  void
 */
VOID Audio_Player_Destory(VOID *pDesc)
{
    UI_Audio_Player_Desc_t *pAudioPlayer   = g_AudioPlayerGlobalCtrl.pChart;
    if(NULL != pAudioPlayer->VolEndTask)
    {
        lv_task_del(pAudioPlayer->VolEndTask);
        pAudioPlayer->VolEndTask = NULL;
    }
    Hal_Mem_Set(&g_AudioPlayerGlobalCtrl, 0, sizeof(Audio_Player_Global_Ctrl_t));
#if 0
    if(AUDIO_PLAYER_STATE_RUN == ap_state)
    {
        Hal_File_Play_End();
        if(NULL != audio_player_task_p)
        {
            lv_task_del(audio_player_task_p);
            audio_player_task_p = NULL;
        }
        ap_state = AUDIO_PLAYER_STATE_PAUSE;
        Framework_Set_Sleep_Lcd_Only(FALSE);
    }
#endif

#if USE_LV_SD_FS
    if((true == sd_remount_flg) && (AUDIO_PLAYER_STATE_RUN != ap_state))
    {
        printf("%s,SD card is released by user!\n",__FUNCTION__);
        HAL_sd_user_set(false);
        sd_remount_flg = false;
    }
#endif
}

static void audio_player_task(lv_task_t * task)
{
    if(AUDIO_PLAYER_STATE_RUN != ap_state)
    {
        return;
    }

    audio_player_display_time();
}

/**
 * Common Process UI Create event
 * param (in) pDesc:  VOID *
 * return  void
 */
VOID Audio_Player_Create_On_Create(VOID *pDesc)
{
    g_AudioPlayerGlobalCtrl.pChart   = pDesc;

    audio_player_get_endtime();
    audio_player_auto_user_interface_update();
    if((AUDIO_PLAYER_STATE_RUN == ap_state) && (NULL == audio_player_task_p)) {
        audio_player_task_p = lv_task_create(audio_player_task, 1000, LV_TASK_PRIO_MID, NULL);
    }
}

/**
 * Common Process UI save event
 * param (in) pDesc:  VOID *
 * return  void
 */
VOID Audio_Player_Create_On_Save(VOID *pDesc)
{
    g_AudioPlayerGlobalCtrl.pChart   = pDesc;
}

/**
 * entry of audio player APP
 * param (in) void
 * return  void
 */
static VOID Audio_Player_Main(VOID)
{
    Nav_Func_List_t            FuncList;
    UI_Audio_Player_Desc_t *pAudioPlayer   = NULL;

    pAudioPlayer = (UI_Audio_Player_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Audio_Player_Desc_t));
    Hal_Mem_Set(pAudioPlayer, 0, sizeof(UI_Audio_Player_Desc_t));

    pAudioPlayer->TitleLabel.TxtId = LV_LANG_TXT_ID_NONE;
    pAudioPlayer->TitleLabel.TxtAlign = LV_LABEL_ALIGN_CENTER;

    pAudioPlayer->TimeLabel.TxtId = LV_LANG_TXT_ID_NONE;
    pAudioPlayer->TimeLabel.TxtAlign = LV_LABEL_ALIGN_CENTER;

    pAudioPlayer->ProgressSlider.Range = 10;
    pAudioPlayer->ProgressSlider.Value = 0;

    pAudioPlayer->BtnBar.ButtonL.TxtId = PHONE_TEXT_ID_OPT;
    pAudioPlayer->BtnBar.ButtonL.Valid = true;

    pAudioPlayer->BtnBar.ButtonM.TxtId = PHONE_TEXT_ID_PLAY;
    pAudioPlayer->BtnBar.ButtonM.Valid = true;

    pAudioPlayer->BtnBar.ButtonR.TxtId = PHONE_TEXT_ID_BACK;
    pAudioPlayer->BtnBar.ButtonR.Valid = true;

    pAudioPlayer->KeyFunc = Audio_Player_Main_Handle;

    FuncList.OnShow         = (Void_P_Func_t)UI_Audio_NoTitle_Labels_Bar_Create;
    FuncList.OnHide         = NULL;
    FuncList.OnCreate       = Audio_Player_Create_On_Create;
    FuncList.OnDestroy      = Audio_Player_Destory; // temp
    FuncList.OnSaveState    = Audio_Player_Create_On_Save;              // temp
    FuncList.OnRestoreState = Audio_Player_Create_On_Create;           // temp

    // APP UI entry
    Nav_Forward(ACT_ID_ANY, ACT_ID_AUDIO_PLAYER, &FuncList, (void *)pAudioPlayer);
}

#if USE_LV_SD_FS
/**
 * entry of audio player APP
 * param (in) void
 * return  void
 */
static UINT8 Audio_Player_Mounted_As_Storage_Handle(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val)
{
    UINT8 Result = 0;

    // handle the return key
    if (KEY_RELEASED == key_sta)
    {
        if (KEY_SOFTRIGHT == key_val)
        {
            Nav_Back(ACT_ID_ANY);
            Result = 1;
        }
        else if (KEY_END == key_val)
        {
            Nav_Home(ACT_ID_ANY);
            Result = 1;
        }
    }

    return(Result);   // temp
}

/**
 * Common Process UI Create event
 * param (in) pDesc:  VOID *
 * return  void
 */
static VOID Audio_Player_Mounted_As_Storage_On_Create(VOID *pDesc)
{
    UI_Normal_NoTitle_Desc_t *pAudioPlayerMounted = pDesc;

    lv_label_set_long_mode(pAudioPlayerMounted->ContenCont.ContLabel.Label,
                                LV_LABEL_LONG_BREAK);
}

/**
 * entry of audio player APP
 * param (in) void
 * return  void
 */
static VOID Audio_Player_Mounted_As_Storage(VOID)
{
    Nav_Func_List_t          FuncList;
    UI_Normal_NoTitle_Desc_t *pAudioPlayerMounted = NULL;

    pAudioPlayerMounted = (UI_Normal_NoTitle_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Normal_NoTitle_Desc_t));
    Hal_Mem_Set(pAudioPlayerMounted, 0, sizeof(UI_Normal_NoTitle_Desc_t));

    pAudioPlayerMounted->ContenCont.ContLabel.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
    pAudioPlayerMounted->ContenCont.ContLabel.TxtId      = PHONE_TEXT_ID_SD_MOUNTED_AS_U_STORAGE;
    pAudioPlayerMounted->ContenCont.ContLabel.TxtAlign   = LV_LABEL_ALIGN_LEFT;
    pAudioPlayerMounted->ContenCont.ContLabelAlign       = LV_ALIGN_IN_TOP_LEFT;

    pAudioPlayerMounted->ButtonBar.ButtonR.TxtId = PHONE_TEXT_ID_BACK;
    pAudioPlayerMounted->ButtonBar.ButtonR.Valid = true;

    pAudioPlayerMounted->KeyFunc = Audio_Player_Mounted_As_Storage_Handle;

    FuncList.OnShow         = (Void_P_Func_t)UI_Normal_NoTitle_Create;
    FuncList.OnHide         = NULL;
    FuncList.OnCreate       = Audio_Player_Mounted_As_Storage_On_Create;
    FuncList.OnDestroy      = NULL;                     // temp
    FuncList.OnSaveState    = NULL;                        // temp
    FuncList.OnRestoreState = Audio_Player_Mounted_As_Storage_On_Create; // temp

    Nav_Forward(ACT_ID_ANY, ACT_ID_AUDIO_PLAYER_MOUNTED_AS_USB, &FuncList, (void *)pAudioPlayerMounted);
}
#endif

/**
 * dummy entry of audio player APP
 * param (in) void
 * return  void
 */
static VOID Audio_Player_Dummy_Main(VOID)
{
#if USE_LV_SD_FS
    if(true != sd_remount_flg)
    {
        if(AUDIO_SD_MOUNTED_AS_U_STORAGE == HAL_sd_user_set(true))
        {
            printf("%s,SD card is mounted as U storage!\n",__FUNCTION__);
            Audio_Player_Mounted_As_Storage();
        }
        else
        {
            printf("%s,SD card is not mounted as U storage!\n",__FUNCTION__);
            sd_remount_flg = true;
            Audio_Player_Main();
        }
    }
    else
    {
        Audio_Player_Main();
    }
#else
    Audio_Player_Main();
#endif
}

/**
 * initiate audio player module
 * param (in) void
 * return  void
 */
VOID Audio_Player_Init_Req(VOID)
{
    If_Framework_Reg_Info_t *RegInfo = NULL;

    // init global variable
    Hal_Mem_Set(&g_AudioPlayerGlobalCtrl, 0, sizeof(Audio_Player_Global_Ctrl_t));
    Hal_Mem_Set(&current_playinfo, 0, sizeof(hal_play_info_t));

    RegInfo = (If_Framework_Reg_Info_t *)Hal_Mem_Alloc(sizeof(If_Framework_Reg_Info_t));
    Hal_Mem_Set(RegInfo, 0, sizeof(If_Framework_Reg_Info_t));
    RegInfo->AppFunc    = Audio_Player_Dummy_Main;
    RegInfo->NameTextId = PHONE_TEXT_ID_AUDIO_PLAYER;
    RegInfo->AppImage   = IMG_MENU_MUSIC;
    Framework_App_Register_Req(RegInfo);
}
